package com.project.Log;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import cgw.Doctorshift;
import com.Entity.DzmHisMemberEntity;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
@Controller
@CrossOrigin(value = { "*" },allowCredentials = "true")
class LoginWeb {

    @Reference
   private Doctorshift dis;

    @Resource
    private RedisTemplate<String,DzmHisMemberEntity> redisTemplate;

    @RequestMapping("login")
    @ResponseBody
    public  String login(DzmHisMemberEntity u, HttpServletResponse response){
        DzmHisMemberEntity users = dis.query(u);
        String tokenId = null;
        if (users!=null) {
            tokenId = UUID.randomUUID().toString();
            ValueOperations<String, DzmHisMemberEntity> ops = redisTemplate.opsForValue();
            ops.set(tokenId, users);
        }
        String re = null;
        if (tokenId!= null) {
            Cookie cookie = new Cookie("token", tokenId);
            cookie.setDomain("localhost");
            cookie.setPath("/");
            response.addCookie(cookie);
            re = "1";
        }
        return re;
    }
}
